//
//  ViewController.m
//  TestNavigation
//
//  Created by xuzhiming on 2016/11/30.
//  Copyright © 2016年 xuzhiminglongma. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (strong, nonatomic) IBOutlet UILabel *labelViewInfo;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)onSwitchChange:(id)sender {
    UISwitch *sw = (UISwitch*)sender;
    // 不透明的话，会导致View的Frame从导航栏底部开始
    // 此时设置self.edgesForExtendedLayout = UIRectEdgeAll;无效，无法延伸
    self.navigationController.navigationBar.translucent = sw.on;
    [self.labelViewInfo setText:[NSString stringWithFormat:@"View Frame: %@", NSStringFromCGRect(self.view.frame)]];
}

- (IBAction)onHideShowImage:(id)sender {
    // 根据setShowImage函数说明，一定要BackgroundImage也是自定义的时候才有效
    // 此时导航栏会变成完全透明
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
- (IBAction)onHideShowImage2:(id)sender {
    for (UIView *view in [self.navigationController.navigationBar subviews]) {
        if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
            for (UIView *v in [view subviews]) {
                if ([v isKindOfClass:[UIImageView class]]) {
                    v.hidden = YES;
                }
            }
        }
    }

}
- (IBAction)onSetBackgroundColor:(id)sender {
    self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
}

- (IBAction)onSliderChange:(id)sender {
    UISlider *slider = (UISlider*)sender;
    UIView *navBackgroundView = [self.navigationController.navigationBar subviews][0];
    navBackgroundView.alpha = 1 - (slider.value / 100);
}

@end



